import java.util.Arrays;

/**
 * @author LKQ
 * @date 2021/12/26 15:31
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] nums1 = {1,3}, nums2 = {2};
        solution.findMedianSortedArrays(nums1, nums2);
    }

    public double findMedianSortedArrays(int[] nums1, int[] nums2) {
        int m = nums1.length, n = nums2.length;
        int[] arr = new int[m+n];
        for (int i = 0; i < m+n; i++) {
            if (i < m) {
                arr[i] = nums1[i];
            }else {
                arr[i] = nums2[i-m];
            }
        }
        Arrays.sort(arr);
        double ans = 0;
        if (arr.length % 2 == 0) {
            // 为偶数
            ans = (arr[(arr.length - 1) / 2] + arr[(arr.length - 1) / 2 + 1]) / 2.0;
        }else {
            // 为奇数
            ans = arr[arr.length / 2];
        }
        return ans;
    }
}
